/**
* Copyright @ 2023 iAuto (Shanghai) Co., Ltd.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are NOT permitted except as agreed by
* iAuto (Shanghai) Co., Ltd.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/



import request from '@/utils/request';
import { IPromiseApi, IPromiseListApi } from '@/types/type';
import {
  IOneCarOneGearList,
  IOneCarOneGearListParam,
  IOneCarOneGearSceneDetail,
  IOneCarOneGearSceneItem,
  IOneCarOneGearSceneList,
  IOneCarOneGearSceneListParam,
  IOneCarOneGearTabEnum
} from '@/types/oneCarOneGearScene';
import base from './base';
// import {ISceneAuditDetail} from "@/types/sceneAudit";

// 新增背景图
export async function oneCarOneGearSceneDetail(sceneUuid: string) {
  return await request.get<IPromiseApi<IOneCarOneGearSceneDetail>>(
    `/${base.API}/ms-soa-custom-scene/${base.VERSION}/admin/scenes/detail`,{
      params:{
        sceneUuid
      }
    }
  );
}

//一车一档场景列表查看
export async function getOneCarOneGearSceneList({
  current,
  pageSize,
}: IOneCarOneGearSceneListParam) {
  const {
    data
  } = await request.get<IPromiseListApi<IOneCarOneGearSceneList>>(
    `/${base.API}/ms-soa-custom-scene/${base.VERSION}/admin/scenes`,
    {
      params: {
        pageSize,
        pageNumber: current,
      },
    },
  );
  return {
    list: data?.itemSize
      ? data?.dataList.map((item: IOneCarOneGearSceneItem, index: number) => ({
          ...item,
          index: index + 1 + (current - 1) * pageSize,
        }))
      : [],
    total: data?.pageCount,
  };
}

//一车一档场景列表查看
export async function getOneCarOneGearSceneVehicleList(
  params: IOneCarOneGearListParam) {
  return await request.get<IPromiseApi<IOneCarOneGearList>>(
    `/${base.API}/ms-soa-vehicle/${base.VERSION}/admin/vehicle/page`,
    {
      params: {
        ...params,
        pagesize: 15,
        current: 1
      },
    },
  );
}

//一车一档Tab页列表
export async function getOneCarOneGearTabList(url: string, params: any) {
  const urlMap = {
    [IOneCarOneGearTabEnum[1]]: '/api/ms-soa-service/v1/admin/service/vinService/list',
    [IOneCarOneGearTabEnum[2]]: '/api/ms-soa-skill/v1/admin/skill/vinSkill/list',
    [IOneCarOneGearTabEnum[3]]: '/api/ms-soa-custom-scene/v2/admin/scenes'
  };
  return await request.get<IPromiseApi<any>>(`${urlMap[url]}`, {
    params,
  });
}
// 查看用户信息
export async function getCarCellPhone(vin: any) {
  return await request.get<IPromiseApi<any>>(`${base.GATEWAY}/account/soa/userInfo/getMobileByVin`, {
    params:{
      vin
    },
  });
}

// 手机号
export async function getOneCarOneCellPhone(mobile: any) {
  return await request.get<IPromiseApi<any>>(`${base.GATEWAY}/account/soa/deviceInfo/getByUserMobile`, {
    params:{
      mobile
    }
  });
}
